import { PromptTemplate, FewShotPromptTemplate } from "@langchain/core/prompts";

const examples = [
  { input: "apple", output: "苹果" },
  { input: "banana", output: "香蕉" },
  { input: "orange", output: "橙子" },
];

// 每个示例的模板
const examplePt = PromptTemplate.fromTemplate(
  "输入: {input} --- 输出: {output}"
);

const pt = new FewShotPromptTemplate({
  examples, // 示例的数组
  examplePrompt: examplePt, // 示例的模板
  suffix: "输入: {fruit} --- 输出: ",
  inputVariables: ["fruit"],
});

const result = await pt.format({
  fruit: "grape",
});
console.log(result);
